package demo;
import java.util.concurrent.atomic.AtomicStampedReference;

class Book {
    private String title;
    private double price;

    public Book(String title, double price) {
        this.title = title;
        this.price = price;
    }

    @Override
    public String toString() {
        return "【图书】名称 = " + this.title + "、价格 = " + this.price;
    }
}

public class YootkDemop243 {
    public static void main(String[] args) throws Exception {
        Book book = new Book("Java进阶开发实战", 69.8);
        AtomicStampedReference<Book> ref = new AtomicStampedReference<Book>(book, 1);
        ref.compareAndSet(book, new Book("Spring开发实战", 67.8), 1, 2);
        System.out.println(ref.getReference());
        System.out.println("当前版本号: " + ref.getStamp());
    }
}
